package cn.com.sinux.spring.json;

import cn.com.sinux.spring.commons.PropertyCollection;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;

/**
 * Created by Administrator on 2016/2/4.
 */
public class JsonFilter {

    public static String doPropertyFilter(Object obj, String... ingo) {
        SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
        for (String pr : ingo) {
            simplePropertyPreFilter.getExcludes().add(pr);
        }
        return JSONObject.toJSONString(obj, simplePropertyPreFilter);
    }

    public static String doPropertyFilter(Object obj, PropertyCollection propertyCollection) {
        SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
        simplePropertyPreFilter.getExcludes().addAll(propertyCollection.getProperties());
        return JSONObject.toJSONString(obj, simplePropertyPreFilter);
    }
}
